<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>实验管理系统 - 计算机系统基础</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="css/index.css">
</head>

<body>
    <!-- 导航栏 -->
    <nav class="navbar">
        <div class="logo-container">
            <i class="fas fa-flask"></i>
            <h1>实验管理系统</h1>
        </div>

        <ul class="nav-links">
            <li><a href="#" class="active">首页</a></li>
            <li><a href="#experiment-section">实验列表</a></li>
            <li><a href="#teaching-resources">教学资源</a></li>
            <li><a href="#about-us">关于我们</a></li>
            <li><a href="#help-center">帮助中心</a></li> <!-- 更新链接 -->
        </ul>

        <div class="auth-buttons">
            <button class="login-btn">
                <i class="fas fa-sign-in-alt"></i>登录
            </button>
            <button class="register-btn">
                <i class="fas fa-user-plus"></i>注册
            </button>
        </div>
    </nav>

    <!-- 英雄区域 -->
    <section class="hero">
        <h2>探索计算机系统基础的实验世界</h2>
        <p>提供全面的实验教学资源、指导视频和实验文件下载，助力您的学习之旅</p>
        <div class="hero-buttons">
            <button class="btn btn-primary">
                <i class="fas fa-flask"></i>查看实验
            </button>
            <button class="btn btn-secondary">
                <i class="fas fa-video"></i>观看教程
            </button>
        </div>
    </section>

    <!-- 实验展示区 -->
    <section class="section" id="experiment-section">
        <div class="section-title">
            <h2>计算机系统基础实验</h2>
            <p>精心设计的实验项目，帮助您深入理解计算机系统底层原理</p>
        </div>

        <div class="course-nav">
            <button class="course-btn active" data-course="all">全部实验</button>
            <button class="course-btn" data-course="cs">计算机系统基础</button>
            <button class="course-btn" data-course="os">操作系统</button>
            <button class="course-btn" data-course="net">计算机网络</button>
            <button class="course-btn" data-course="ai">人工智能</button>
        </div>

        <div class="experiments-container" id="experiments-container">
            <!-- 实验卡片将由JavaScript动态生成 -->
            <div class="loading-indicator">
                <i class="fas fa-spinner fa-spin"></i> 正在加载实验数据...
            </div>
        </div>
    </section>

    <!-- 实验详情区（默认隐藏） -->
    <section class="section" id="experiment-detail-section" style="display: none;">
        <div class="section-title">
            <h2 id="detail-title">实验详情</h2>
            <p id="detail-subtitle">查看实验资料、指导视频和相关资源</p>
        </div>

        <div class="experiment-detail" id="experiment-detail">
            <div class="close-detail" onclick="hideExperimentDetail()">
                <i class="fas fa-times"></i>
            </div>
            <div class="detail-header">
                <h2 id="detail-experiment-title">数据结构与算法实验</h2>
                <p id="detail-experiment-description">通过实现各种数据结构和算法，加深对计算机科学基础的理解，提升编程能力。</p>
            </div>
            <div class="detail-content">
                <div class="detail-main">
                    <h3><i class="fas fa-info-circle"></i> 实验介绍</h3>
                    <p id="detail-full-description">
                        本实验旨在帮助学生掌握基本数据结构和算法的实现与应用。实验内容包括数组、链表、栈、队列、树、图等数据结构的实现，以及排序、搜索等常用算法的设计与分析。</p>

                    <h3><i class="fas fa-tasks"></i> 实验目标</h3>
                    <ul id="detail-objectives">
                        <li>理解各种数据结构的特点和适用场景</li>
                        <li>掌握常见算法的实现原理和时间复杂度分析</li>
                        <li>能够根据问题需求选择合适的数据结构和算法</li>
                        <li>提升编程能力和问题解决能力</li>
                    </ul>

                    <h3><i class="fas fa-video"></i> 实验指导视频</h3>
                    <div class="video-container">
                        <div class="video-placeholder">
                            <i class="fas fa-play-circle" style="font-size: 2rem; margin-right: 10px;"></i>
                            实验指导视频预览
                        </div>
                    </div>
                </div>

                <div class="detail-sidebar">
                    <div class="resources-card">
                        <h3><i class="fas fa-file-download"></i> 实验文件下载</h3>
                        <ul class="resource-list" id="resource-list">
                            <li>
                                <div class="resource-name">
                                    <i class="fas fa-file-pdf"></i>
                                    <span>实验指导手册.pdf</span>
                                </div>
                                <button class="download-btn">
                                    <i class="fas fa-download"></i> 下载
                                </button>
                            </li>
                            <li>
                                <div class="resource-name">
                                    <i class="fas fa-file-code"></i>
                                    <span>实验代码模板.zip</span>
                                </div>
                                <button class="download-btn">
                                    <i class="fas fa-download"></i> 下载
                                </button>
                            </li>
                            <li>
                                <div class="resource-name">
                                    <i class="fas fa-file-alt"></i>
                                    <span>实验报告模板.docx</span>
                                </div>
                                <button class="download-btn">
                                    <i class="fas fa-download"></i> 下载
                                </button>
                            </li>
                        </ul>
                    </div>

                    <div class="resources-card">
                        <h3><i class="fas fa-link"></i> 相关资源</h3>
                        <ul class="resource-list">
                            <li>
                                <div class="resource-name">
                                    <i class="fas fa-book"></i>
                                    <span>数据结构与算法分析（电子书）</span>
                                </div>
                            </li>
                            <li>
                                <div class="resource-name">
                                    <i class="fas fa-laptop-code"></i>
                                    <span>在线编程练习平台</span>
                                </div>
                            </li>
                            <li>
                                <div class="resource-name">
                                    <i class="fas fa-question-circle"></i>
                                    <span>常见问题解答</span>
                                </div>
                            </li>
                        </ul>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- 教学资源区域 -->
    <section class="section" id="teaching-resources">
        <div class="section-title">
            <h2>教学资源中心</h2>
            <p>丰富多样的教学资源，助力您的学习与研究</p>
        </div>

        <!-- 视频资源 -->
        <div class="resource-category">
            <h3><i class="fas fa-video" style="color: #e74c3c;"></i> 视频资源</h3>
            <div class="resource-grid">
                <div class="resource-item">
                    <div class="resource-icon">
                        <i class="fas fa-desktop"></i>
                    </div>
                    <div class="resource-content">
                        <h4>数据表示与运算实验详解</h4>
                        <p>详细讲解整数补码表示、浮点数IEEE 754标准实现及位级运算</p>
                        <span class="tag">计算机系统基础</span>
                    </div>
                </div>

                <div class="resource-item">
                    <div class="resource-icon">
                        <i class="fas fa-bug"></i>
                    </div>
                    <div class="resource-content">
                        <h4>BinaryBomb拆解技巧</h4>
                        <p>GDB调试实战，教你如何一步步拆解二进制炸弹</p>
                        <span class="tag">计算机系统基础</span>
                    </div>
                </div>

                <div class="resource-item">
                    <div class="resource-icon">
                        <i class="fas fa-shield-alt"></i>
                    </div>
                    <div class="resource-content">
                        <h4>缓冲区溢出攻击与防御</h4>
                        <p>AttackLab实验中的攻击原理及现代防护机制解析</p>
                        <span class="tag">计算机系统基础</span>
                    </div>
                </div>

                <div class="resource-item">
                    <div class="resource-icon">
                        <i class="fas fa-link"></i>
                    </div>
                    <div class="resource-content">
                        <h4>ELF文件链接过程解析</h4>
                        <p>深入讲解静态链接与动态链接的底层实现差异</p>
                        <span class="tag">计算机系统基础</span>
                    </div>
                </div>
            </div>
        </div>

        <!-- 电子书资源 -->
        <div class="resource-category">
            <h3><i class="fas fa-book" style="color: #3498db;"></i> 电子书资源</h3>
            <div class="resource-grid">
                <div class="resource-item">
                    <div class="resource-icon">
                        <i class="fas fa-file-pdf"></i>
                    </div>
                    <div class="resource-content">
                        <h4>深入理解计算机系统</h4>
                        <p>计算机科学经典教材，涵盖系统底层原理</p>
                        <span class="tag">PDF · 12MB</span>
                    </div>
                </div>

                <div class="resource-item">
                    <div class="resource-icon">
                        <i class="fas fa-file-alt"></i>
                    </div>
                    <div class="resource-content">
                        <h4>计算机系统基础实验指南</h4>
                        <p>系统实验操作手册与原理详解</p>
                        <span class="tag">PDF · 8MB</span>
                    </div>
                </div>

                <div class="resource-item">
                    <div class="resource-icon">
                        <i class="fas fa-file-code"></i>
                    </div>
                    <div class="resource-content">
                        <h4>汇编语言程序设计</h4>
                        <p>x86汇编语言编程指南与实例分析</p>
                        <span class="tag">PDF · 15MB</span>
                    </div>
                </div>

                <div class="resource-item">
                    <div class="resource-icon">
                        <i class="fas fa-network-wired"></i>
                    </div>
                    <div class="resource-content">
                        <h4>操作系统原理与实践</h4>
                        <p>操作系统核心概念与实现细节</p>
                        <span class="tag">PDF · 10MB</span>
                    </div>
                </div>
            </div>
        </div>

        <!-- 练习资源 -->
        <div class="resource-category">
            <h3><i class="fas fa-pencil-alt" style="color: #27ae60;"></i> 练习题库</h3>
            <div class="resource-grid">
                <div class="resource-item">
                    <div class="resource-icon">
                        <i class="fas fa-calculator"></i>
                    </div>
                    <div class="resource-content">
                        <h4>数据表示练习题</h4>
                        <p>补码、浮点数表示与位运算练习题集</p>
                        <span class="tag">120题</span>
                    </div>
                </div>

                <div class="resource-item">
                    <div class="resource-icon">
                        <i class="fas fa-microchip"></i>
                    </div>
                    <div class="resource-content">
                        <h4>汇编语言练习题</h4>
                        <p>x86汇编指令、程序分析与调试练习</p>
                        <span class="tag">85题</span>
                    </div>
                </div>

                <div class="resource-item">
                    <div class="resource-icon">
                        <i class="fas fa-code"></i>
                    </div>
                    <div class="resource-content">
                        <h4>缓冲区溢出挑战</h4>
                        <p>CTF风格的缓冲区溢出实战练习题</p>
                        <span class="tag">30题</span>
                    </div>
                </div>

                <div class="resource-item">
                    <div class="resource-icon">
                        <i class="fas fa-cogs"></i>
                    </div>
                    <div class="resource-content">
                        <h4>链接与装载练习题</h4>
                        <p>ELF文件结构、符号解析与重定位练习</p>
                        <span class="tag">65题</span>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- 关于我们区域（更新为广东东软学院信息） -->
    <section class="section" id="about-us">
        <div class="section-title">
            <h2>关于我们</h2>
            <p>优秀的教师团队，培养卓越的计算机人才</p>
        </div>

        <div class="about-container">
            <!-- 学校简介 -->
            <div class="about-section">
                <h3><i class="fas fa-university" style="color: #2c3e50;"></i> 学校简介</h3>
                <p>广东东软学院是经教育部批准设立的全日制普通高等本科学校，成立于2002年。学校位于广东省佛山市南海区，是广东省首批省级示范性软件学院。</p>
                <p>计算机学院是学校重点建设学院，拥有省级重点专业和特色专业。学院现有教职工150余人，其中教授15人，副教授35人。拥有省级实验教学示范中心1个，省部级重点实验室2个。近年来，学院承担国家级科研项目30余项，发表高水平论文200余篇。
                </p>
            </div>

            <!-- 教授列表 -->
            <div class="about-section">
                <h3><i class="fas fa-user-tie" style="color: #e74c3c;"></i> 教授列表</h3>
                <div class="teacher-grid">
                    <div class="teacher-card">
                        <img src="https://randomuser.me/api/portraits/men/32.jpg" alt="张教授" class="teacher-avatar">
                        <h4>张明华</h4>
                        <div class="position">教授/计算机学院院长</div>
                        <div class="research">研究方向：人工智能与大数据</div>
                    </div>

                    <div class="teacher-card">
                        <img src="https://randomuser.me/api/portraits/women/44.jpg" alt="李教授" class="teacher-avatar">
                        <h4>李静怡</h4>
                        <div class="position">教授/副院长</div>
                        <div class="research">研究方向：计算机网络与安全</div>
                    </div>

                    <div class="teacher-card">
                        <img src="https://randomuser.me/api/portraits/men/62.jpg" alt="王教授" class="teacher-avatar">
                        <h4>王建国</h4>
                        <div class="position">教授/学术委员会主任</div>
                        <div class="research">研究方向：软件工程</div>
                    </div>

                    <div class="teacher-card">
                        <img src="https://randomuser.me/api/portraits/women/68.jpg" alt="陈教授" class="teacher-avatar">
                        <h4>陈晓梅</h4>
                        <div class="position">教授/实验室主任</div>
                        <div class="research">研究方向：计算机系统结构</div>
                    </div>
                </div>
            </div>

            <!-- 副教授列表 -->
            <div class="about-section">
                <h3><i class="fas fa-user-graduate" style="color: #3498db;"></i> 副教授列表</h3>
                <div class="teacher-grid">
                    <div class="teacher-card">
                        <img src="https://randomuser.me/api/portraits/men/41.jpg" alt="刘副教授" class="teacher-avatar">
                        <h4>刘志强</h4>
                        <div class="position">副教授</div>
                        <div class="research">研究方向：嵌入式系统</div>
                    </div>

                    <div class="teacher-card">
                        <img src="https://randomuser.me/api/portraits/women/32.jpg" alt="杨副教授" class="teacher-avatar">
                        <h4>杨雪</h4>
                        <div class="position">副教授</div>
                        <div class="research">研究方向：分布式系统</div>
                    </div>

                    <div class="teacher-card">
                        <img src="https://randomuser.me/api/portraits/men/22.jpg" alt="赵副教授" class="teacher-avatar">
                        <h4>赵刚</h4>
                        <div class="position">副教授</div>
                        <div class="research">研究方向：计算机组成原理</div>
                    </div>

                    <div class="teacher-card">
                        <img src="https://randomuser.me/api/portraits/women/28.jpg" alt="孙副教授" class="teacher-avatar">
                        <h4>孙丽</h4>
                        <div class="position">副教授</div>
                        <div class="research">研究方向：系统性能优化</div>
                    </div>
                </div>
            </div>

            <!-- 实验指导老师列表 -->
            <div class="about-section">
                <h3><i class="fas fa-user" style="color: #27ae60;"></i> 实验指导老师列表</h3>
                <div class="teacher-grid">
                    <div class="teacher-card">
                        <img src="https://randomuser.me/api/portraits/men/65.jpg" alt="周老师" class="teacher-avatar">
                        <h4>周涛</h4>
                        <div class="position">高级实验师</div>
                        <div class="research">负责：计算机系统基础实验</div>
                    </div>

                    <div class="teacher-card">
                        <img src="https://randomuser.me/api/portraits/women/65.jpg" alt="吴老师" class="teacher-avatar">
                        <h4>吴敏</h4>
                        <div class="position">实验师</div>
                        <div class="research">负责：操作系统实验</div>
                    </div>

                    <div class="teacher-card">
                        <img src="https://randomuser.me/api/portraits/men/75.jpg" alt="郑老师" class="teacher-avatar">
                        <h4>郑浩</h4>
                        <div class="position">高级实验师</div>
                        <div class="research">负责：计算机网络实验</div>
                    </div>

                    <div class="teacher-card">
                        <img src="https://randomuser.me/api/portraits/women/55.jpg" alt="钱老师" class="teacher-avatar">
                        <h4>钱芳</h4>
                        <div class="position">实验师</div>
                        <div class="research">负责：人工智能实验</div>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- 新增帮助中心 -->
    <section class="section" id="help-center">
        <div class="section-title">
            <h2>帮助中心</h2>
            <p>常见问题解答与系统使用指南</p>
        </div>

        <div class="help-center">
            <h3><i class="fas fa-question-circle"></i> 常见问题分类</h3>

            <div class="help-categories">
                <div class="help-category">
                    <h4><i class="fas fa-user-circle"></i> 账号与登录</h4>
                    <ul class="help-questions">
                        <li><i class="fas fa-question"></i><a href="#">如何注册账号？</a></li>
                        <li><i class="fas fa-question"></i><a href="#">忘记密码怎么办？</a></li>
                        <li><i class="fas fa-question"></i><a href="#">如何修改个人信息？</a></li>
                        <li><i class="fas fa-question"></i><a href="#">账号安全设置</a></li>
                    </ul>
                </div>

                <div class="help-category">
                    <h4><i class="fas fa-flask"></i> 实验操作</h4>
                    <ul class="help-questions">
                        <li><i class="fas fa-question"></i><a href="#">如何开始一个新实验？</a></li>
                        <li><i class="fas fa-question"></i><a href="#">实验环境配置指南</a></li>
                        <li><i class="fas fa-question"></i><a href="#">实验提交与评分标准</a></li>
                        <li><i class="fas fa-question"></i><a href="#">实验报告撰写规范</a></li>
                    </ul>
                </div>

                <div class="help-category">
                    <h4><i class="fas fa-download"></i> 资源下载</h4>
                    <ul class="help-questions">
                        <li><i class="fas fa-question"></i><a href="#">如何下载实验资料？</a></li>
                        <li><i class="fas fa-question"></i><a href="#">下载文件格式说明</a></li>
                        <li><i class="fas fa-question"></i><a href="#">资源无法下载的解决方法</a></li>
                        <li><i class="fas fa-question"></i><a href="#">实验代码使用说明</a></li>
                    </ul>
                </div>

                <div class="help-category">
                    <h4><i class="fas fa-exclamation-triangle"></i> 故障排除</h4>
                    <ul class="help-questions">
                        <li><i class="fas fa-question"></i><a href="#">页面加载异常怎么办？</a></li>
                        <li><i class="fas fa-question"></i><a href="#">实验环境无法启动</a></li>
                        <li><i class="fas fa-question"></i><a href="#">提交实验时出错</a></li>
                        <li><i class="fas fa-question"></i><a href="#">视频无法播放的解决方案</a></li>
                    </ul>
                </div>

                <div class="help-category">
                    <h4><i class="fas fa-book"></i> 学习指南</h4>
                    <ul class="help-questions">
                        <li><i class="fas fa-question"></i><a href="#">实验系统使用手册</a></li>
                        <li><i class="fas fa-question"></i><a href="#">计算机系统基础学习路线</a></li>
                        <li><i class="fas fa-question"></i><a href="#">实验常见问题集锦</a></li>
                        <li><i class="fas fa-question"></i><a href="#">如何高效完成实验项目？</a></li>
                    </ul>
                </div>

                <div class="help-category">
                    <h4><i class="fas fa-cog"></i> 系统设置</h4>
                    <ul class="help-questions">
                        <li><i class="fas fa-question"></i><a href="#">如何修改个人设置？</a></li>
                        <li><i class="fas fa-question"></i><a href="#">通知设置与管理</a></li>
                        <li><i class="fas fa-question"></i><a href="#">实验进度跟踪功能</a></li>
                        <li><i class="fas fa-question"></i><a href="#">界面个性化设置</a></li>
                    </ul>
                </div>
            </div>
        </div>
    </section>

    <!-- 特色功能区域 -->
    <section class="section features">
        <div class="section-title">
            <h2>系统特色功能</h2>
            <p>我们为教师和学生提供全方位的实验教学支持</p>
        </div>

        <div class="features-container">
            <div class="feature-card">
                <div class="feature-icon">
                    <i class="fas fa-flask"></i>
                </div>
                <h3>丰富实验资源</h3>
                <p>提供多学科的实验项目，涵盖计算机科学各个领域，每个实验包含详细文档和指导材料。</p>
            </div>

            <div class="feature-card">
                <div class="feature-icon">
                    <i class="fas fa-video"></i>
                </div>
                <h3>高清指导视频</h3>
                <p>每个实验配有专业教师录制的高清指导视频，帮助学生理解实验步骤和关键概念。</p>
            </div>

            <div class="feature-card">
                <div class="feature-icon">
                    <i class="fas fa-cloud-download-alt"></i>
                </div>
                <h3>资源一键下载</h3>
                <p>实验所需的所有文件、代码模板和报告模板均可一键下载，节省时间提高效率。</p>
            </div>
        </div>
    </section>

    <!-- 页脚 -->
    <footer class="footer">
        <div class="footer-content">
            <div class="footer-column">
                <h3>实验管理系统</h3>
                <p style="color: rgba(255,255,255,0.7); margin-bottom: 20px;">提供全面的实验教学资源管理平台，助力计算机科学教育。</p>
                <div class="footer-links">
                    <li><a href="#"><i class="fas fa-envelope"></i> contact@labsys.edu</a></li>
                    <li><a href="#"><i class="fas fa-phone"></i> (123) 456-7890</a></li>
                    <li><a href="#"><i class="fas fa-map-marker-alt"></i> 北京市海淀区学院路</a></li>
                </div>
            </div>

            <div class="footer-column">
                <h3>快速链接</h3>
                <ul class="footer-links">
                    <li><a href="#"><i class="fas fa-chevron-right"></i> 首页</a></li>
                    <li><a href="#experiment-section"><i class="fas fa-chevron-right"></i> 实验列表</a></li>
                    <li><a href="#teaching-resources"><i class="fas fa-chevron-right"></i> 教学资源</a></li>
                    <li><a href="#about-us"><i class="fas fa-chevron-right"></i> 关于我们</a></li>
                    <li><a href="#"><i class="fas fa-chevron-right"></i> 帮助中心</a></li>
                </ul>
            </div>

            <div class="footer-column">
                <h3>实验分类</h3>
                <ul class="footer-links">
                    <li><a href="#"><i class="fas fa-chevron-right"></i> 计算机系统基础</a></li>
                    <li><a href="#"><i class="fas fa-chevron-right"></i> 操作系统</a></li>
                    <li><a href="#"><i class="fas fa-chevron-right"></i> 计算机网络</a></li>
                    <li><a href="#"><i class="fas fa-chevron-right"></i> 人工智能</a></li>
                    <li><a href="#"><i class="fas fa-chevron-right"></i> 数据库系统</a></li>
                </ul>
            </div>

            <div class="footer-column">
                <h3>订阅更新</h3>
                <p style="color: rgba(255,255,255,0.7); margin-bottom: 20px;">订阅我们的通讯，获取最新实验资源和教学动态。</p>
                <div style="display: flex; gap: 10px;">
                    <input type="email" placeholder="您的邮箱地址"
                        style="flex: 1; padding: 12px; border-radius: 5px; border: none;">
                    <button
                        style="background: #3498db; color: white; border: none; padding: 0 20px; border-radius: 5px; cursor: pointer;">订阅</button>
                </div>
            </div>
        </div>

        <div class="copyright">
            &copy; 2025 实验管理系统. 保留所有权利.
        </div>
    </footer>

    <script>
        // 全局变量存储实验数据
        let experiments = {};

        // 从后端API获取实验数据
        async function fetchExperiments() {
            try {
                const response = await fetch('api/tourist/experiments');
                if (!response.ok) {
                    throw new Error(`HTTP错误! 状态: ${response.status}`);
                }
                experiments = await response.json();
                console.log('获取实验数据成功:', experiments);
                renderExperimentCards();
            } catch (error) {
                console.error('获取实验数据失败:', error);
                document.getElementById('experiments-container').innerHTML = `
                    <div class="error-message">
                        <i class="fas fa-exclamation-triangle"></i> 加载实验数据失败，请稍后重试
                    </div>
                `;
            }
        }

        // 渲染实验卡片
        function renderExperimentCards() {
            const container = document.getElementById('experiments-container');
            container.innerHTML = '';

            Object.keys(experiments).forEach(id => {
                const exp = experiments[id];
                const card = document.createElement('div');
                card.className = 'experiment-card animated';
                card.dataset.course = exp.course;
                card.onclick = () => showExperimentDetail(id);

                card.innerHTML = `
                    <div class="card-image">
                        <img src="${exp.imageUrl}" alt="${exp.title}">
                    </div>
                    <div class="card-content">
                        <h3>${exp.title}</h3>
                        <p>${exp.description}</p>
                        <div class="tag">${getCourseName(exp.course)}</div>
                        <div class="card-meta">
                            <span><i class="far fa-clock"></i> ${exp.duration}小时</span>
                            <span><i class="fas fa-download"></i> ${exp.resources.length}个文件</span>
                        </div>
                    </div>
                `;

                container.appendChild(card);
            });

            // 初始化课程筛选功能
            initCourseFilter();
        }

        // 获取课程名称
        function getCourseName(courseCode) {
            const courses = {
                'cs': '计算机系统基础',
                'os': '操作系统',
                'net': '计算机网络',
                'ai': '人工智能'
            };
            return courses[courseCode] || '其他';
        }

        // 初始化课程筛选
        function initCourseFilter() {
            const courseBtns = document.querySelectorAll('.course-btn');
            courseBtns.forEach(btn => {
                btn.addEventListener('click', function () {
                    courseBtns.forEach(b => b.classList.remove('active'));
                    this.classList.add('active');
                    filterExperiments(this.dataset.course);
                });
            });
        }

        // 课程筛选功能
        function filterExperiments(course) {
            const cards = document.querySelectorAll('.experiment-card');
            cards.forEach(card => {
                if (course === 'all' || card.dataset.course === course) {
                    card.style.display = 'flex';
                    card.classList.add('animated');
                } else {
                    card.style.display = 'none';
                }
            });
        }

        // 显示实验详情
        function showExperimentDetail(id) {
            const exp = experiments[id];
            if (!exp) return;

            const expId = exp.id;

            // 更新详情内容
            document.getElementById('detail-title').textContent = exp.title;
            document.getElementById('detail-subtitle').textContent = "查看实验资料、指导视频和相关资源";
            document.getElementById('detail-experiment-title').textContent = exp.title;
            document.getElementById('detail-experiment-description').textContent = exp.description;
            document.getElementById('detail-full-description').textContent = exp.fullDescription;

            // 更新实验目标
            const objectivesList = document.getElementById('detail-objectives');
            objectivesList.innerHTML = '';
            exp.objectives.forEach(obj => {
                const li = document.createElement('li');
                li.textContent = obj;
                objectivesList.appendChild(li);
            });

            // 更新资源列表
            const resourceList = document.getElementById('resource-list');
            resourceList.innerHTML = '';

            // 筛选出公共资源
            const publicResources = exp.resources.filter(res => res.isPublic);
            if (publicResources.length === 0) {
                resourceList.innerHTML = `
                <li class="no-resources">
                    <i class="fas fa-info-circle"></i>
                    <span>本实验暂无公开资源</span>
                </li>
            `;
            } else {
                publicResources.forEach(res => {
                    const li = document.createElement('li');

                    let iconClass = 'fas fa-file';
                    if (res.type === 'pdf') iconClass = 'fas fa-file-pdf';
                    else if (res.type === 'code') iconClass = 'fas fa-file-code';
                    else if (res.type === 'doc') iconClass = 'fas fa-file-word';
                    else if (res.type === 'notebook') iconClass = 'fas fa-book';

                    li.innerHTML = `
                    <div class="resource-name">
                        <i class="${iconClass}"></i>
                        <span>${res.name}</span>
                    </div>
                    <button class="download-btn" data-exp-id="${expId}" data-res-id="${res.id}" data-res-name="${res.name}">
                        <i class="fas fa-download"></i> 下载
                    </button>
                `;
                    resourceList.appendChild(li);
                });
            }

            // 显示详情区域
            document.getElementById('experiment-detail-section').style.display = 'block';
            document.getElementById('experiment-detail').style.display = 'block';

            // 滚动到详情区域
            document.getElementById('experiment-detail-section').scrollIntoView({ behavior: 'smooth' });
        }

        // 隐藏实验详情
        function hideExperimentDetail() {
            document.getElementById('experiment-detail-section').style.display = 'none';
            document.getElementById('experiment-detail').style.display = 'none';
        }

        // 下载材料函数
        function downloadMaterial(experimentId, resourceId, resourceName) {
            // 后端API端点 - 根据实验ID和资源ID获取下载链接
            const apiUrl = `/api/tourist/experiments/${experimentId}/resources/${resourceId}/download`;

            // 创建XMLHttpRequest对象
            const xhr = new XMLHttpRequest();

            // 创建状态消息元素
            const statusMessage = document.createElement('div');
            statusMessage.className = 'status-message';
            statusMessage.style.position = 'fixed';
            statusMessage.style.bottom = '20px';
            statusMessage.style.right = '20px';
            statusMessage.style.padding = '10px 20px';
            statusMessage.style.borderRadius = '5px';
            statusMessage.style.zIndex = '1000';
            statusMessage.style.fontSize = '14px';
            document.body.appendChild(statusMessage);

            // 显示下载中状态
            statusMessage.textContent = '正在准备下载，请稍候...';
            statusMessage.style.backgroundColor = '#3498db';
            statusMessage.style.color = 'white';

            // 配置请求
            xhr.open('GET', apiUrl, true);
            xhr.responseType = 'blob';

            // 加载完成事件
            xhr.addEventListener('load', function () {
                if (xhr.status === 200) {
                    // 从响应头获取文件名
                    const contentDisposition = xhr.getResponseHeader('Content-Disposition');

                    // 创建下载链接
                    const blob = xhr.response;
                    const downloadUrl = URL.createObjectURL(blob);

                    // 创建临时链接并触发下载
                    const a = document.createElement('a');
                    a.href = downloadUrl;
                    a.download = resourceName || '未命名文件';
                    document.body.appendChild(a);
                    a.click();

                    // 清理
                    setTimeout(() => {
                        document.body.removeChild(a);
                        URL.revokeObjectURL(downloadUrl);
                    }, 100);

                    // 更新状态
                    statusMessage.textContent = '下载完成！文件已保存到您的设备';
                    statusMessage.style.backgroundColor = '#27ae60';

                    // 3秒后移除状态消息
                    setTimeout(() => {
                        document.body.removeChild(statusMessage);
                    }, 3000);
                } else {
                    statusMessage.textContent = `下载失败: 服务器返回错误 ${xhr.status}`;
                    statusMessage.style.backgroundColor = '#e74c3c';

                    // 5秒后移除状态消息
                    setTimeout(() => {
                        document.body.removeChild(statusMessage);
                    }, 5000);
                }
            });

            // 错误处理
            xhr.addEventListener('error', function () {
                statusMessage.textContent = '下载失败: 网络错误';
                statusMessage.style.backgroundColor = '#e74c3c';

                setTimeout(() => {
                    document.body.removeChild(statusMessage);
                }, 5000);
            });

            // 进度事件
            xhr.addEventListener('progress', function (event) {
                if (event.lengthComputable) {
                    const percent = Math.round((event.loaded / event.total) * 100);
                    statusMessage.textContent = `下载中: ${percent}%`;
                }
            });

            // 发送请求
            xhr.send();
        };

        // 在实验详情中处理下载按钮点击
        document.addEventListener('click', function (e) {
            if (e.target && e.target.closest('.download-btn')) {
                const button = e.target.closest('.download-btn');
                const expId = button.getAttribute('data-exp-id');
                const resId = button.getAttribute('data-res-id');
                const resName = button.getAttribute('data-res-name');

                if (expId && resId) {
                    console.log(`下载实验${expId}的资源${resId}`);
                    downloadMaterial(expId, resId, resName);
                }
            }
        });


        // 页面加载完成后初始化
        document.addEventListener('DOMContentLoaded', function () {
            fetchExperiments();

            // 课程导航按钮事件
            const courseBtns = document.querySelectorAll('.course-btn');
            courseBtns.forEach(btn => {
                btn.addEventListener('click', function () {
                    courseBtns.forEach(b => b.classList.remove('active'));
                    this.classList.add('active');
                    filterExperiments(this.dataset.course);
                });
            });
        });

        // 检查登录状态
        document.addEventListener('DOMContentLoaded', function () {
            const user = JSON.parse(localStorage.getItem('user'));
            const loginBtn = document.querySelector('.login-btn');

            if (user) {
                loginBtn.innerHTML = `<i class="fas fa-user"></i>${user.name}`;
                loginBtn.onclick = () => {
                    // 显示用户菜单或执行注销
                };
            } else {
                loginBtn.onclick = () => {
                    window.location.href = '/login.html';
                };
            }
        });
    </script>
</body>

</html>